<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../layuiadmin/layui-v2.5.5/layui/css/layui.css" media="all" type="text/css">
</head>
<body>
<form class="layui-form" action="" lay-filter="example">
    <div class="layui-form-item">
        <label class="layui-form-label">开始日期</label>
        <div class="layui-input-inline">
            <input name="workhistoryStartdate" class="layui-input" id="qBeginTime" type="text" placeholder="yyyy-MM-dd" autocomplete="off" lay-verify="date">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">结束日期</label>
        <div class="layui-input-inline">
            <input name="workhistoryEnddate" class="layui-input" id="qEndTime" type="text" placeholder="yyyy-MM-dd" autocomplete="off" lay-verify="date">
        </div>
    </div>
        <div class="layui-form-item">
            <label class="layui-form-label">工作单位</label>
            <div class="layui-input-block">
                <input name="workhistoryWorkunit" class="layui-input" type="text" placeholder="请输入" autocomplete="off" lay-verify="title">
            </div>
        </div>
           <div class="layui-form-item">
                    <label class="layui-form-label">工作职务</label>
                    <div class="layui-input-block">
                        <input name="workhistoryJobPosition" class="layui-input" type="text" placeholder="请输入" autocomplete="off" lay-verify="title">
                    </div>
                </div>
    <div class="layui-form-item">
        <label class="layui-form-label">工作类别</label>
        <div class="layui-input-block">
            <select name="workhistoryWorktype" lay-filter="aihao" id="position" lay-verify="title1">
                <option value="">请选择</option>
            </select>
        </div>
    </div>
        <div class="layui-form-item">
            <label class="layui-form-label">单位性质</label>
            <div class="layui-input-block">
                <select name="workhistoryWorknature" lay-filter="aihao" id="degree" lay-verify="title1">
                    <option value="">请选择</option>
                </select>
            </div>
        </div>
              <div class="layui-form-item">
                            <label class="layui-form-label">所在地</label>
                            <div class="layui-input-block">
                                <input name="workhistorySite" class="layui-input" type="text" placeholder="请输入" autocomplete="off" lay-verify="title">
                            </div>
                        </div>
        <input type="hidden" name="empId" id="empId">
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" type="submit" lay-filter="demo1" lay-submit="">立即提交</button>
        </div>
    </div>
</form>
<script src="../../layuiadmin/layui-v2.5.5/layui/layui.js" type="text/javascript"></script>
<script type="text/javascript" src="../../layuiadmin/lib/jquery.min.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script type="text/javascript">
    layui.use(['form', 'layedit', 'laydate','upload'], function(){
        var $ = layui.jquery
            ,upload = layui.upload
            ,form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;
        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            ,url: '/upload/'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                //上传成功
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });
        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });
        laydate.render({
            elem: '#date2'
        });
        laydate.render({
            elem: '#date3'
        });
        laydate.render({
            elem: '#date4'
        });
                    laydate.render({	elem: '#qBeginTime',	format: 'yyyy-MM-dd',	done: function (value, date, endDate) {		var startDate = new Date(value).getTime();		var endTime = new Date($('#qEndTime').val()).getTime();		if (endTime < startDate) {			layer.msg('结束时间不能小于开始时间');			$('#qBeginTime').val($('#qEndTime').val());		}	}	})
                       laydate.render({elem: '#qEndTime',	format: 'yyyy-MM-dd',	done: function (value, date, endDate) {		var startDate = new Date($('#qBeginTime').val()).getTime();		var endTime = new Date(value).getTime();		if (endTime < startDate) {			layer.msg('结束时间不能小于开始时间');			$('#qEndTime').val($('#qBeginTime').val());		}	}})
        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');
        //自定义验证规则
        form.verify({
            title: function(value){
                if(value.length < 1){
                    return '请输入';
                }
            }
            ,title1: function(value){
                if(value.length < 1){
                    return '请选择';
                }
            }
            ,pass: [
                /^[\S]{6,12}$/
                ,'密码必须6到12位，且不能出现空格'
            ]
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });
        //工作类别
        $(function(){
            $.ajax({
                type:"POST",
                url:"../../views/hr/json/workleibie.json",
                datatype:"json",
                success:function(data){
                    $.each(data,function (index,item) {
                        $('#position').append("<option value="+item.id+">"+item.id+"</option>");
                    })
                    layui.form.render("select");
                },error:function(){
                    alert("失败")
                }
            })
        })
        //单位性质
        $(function(){
            $.ajax({
                type:"POST",
                url:"../../views/hr/json/workxingzhi.json",
                data:{name:name},
                datatype:"json",
                success:function(data){
                    $.each(data,function (index,item) {
                        $('#degree').append("<option value="+item.id+">"+item.id+"</option>");
                    })
                    layui.form.render("select");
                },error:function(){
                    alert("失败")
                }
            })
        })
        //监听提交
        form.on('submit(demo1)', function(data){
            $.ajax({
                type:"POST",
                url:"http://localhost:8080/HrEmp/workinsert",
                data:data.field,
                datatype:"json",
                async:true,
                success:function(data){
                    layer.alert('添加成功',function(){
                        parent.layer.closeAll();
                    })
                    parent.layui.table.reload('listData1')
                },error:function(){
                    alert("失败")
                }
            });
            return false;
/*            layer.alert(JSON.stringify(data.field), {

                title: '最终的提交信息'
            })
            return false;*/
        });

          var id1=parent.getId();
             $("#empId").val(id1);
        //表单取值
        layui.$('#LAY-component-form-getval').on('click', function(){
            var data = form.val('example');
            alert(JSON.stringify(data));
        });

    });
</script>

</body>
</html>